package com.lxw.station.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lxw.station.core.R;
import com.lxw.station.core.Result;
import com.lxw.station.entity.Lt;
import com.lxw.station.service.LtService;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/lt")
public class LtController {

    @Resource
    LtService ltService;

    /**
     * 新增
     * @param lt
     * @return
     */
    @PostMapping("/lt")
    public Result<Object> save(@RequestBody Lt lt) {
        ltService.save(lt);
        return R.ok(lt);
    }

    /**
     * 根据主键删除
     * @param id
     * @return
     */
    @DeleteMapping("/lt/{id}")
    public Result<Object> removeById(@PathVariable("id") Integer id) {
        ltService.removeById(id);
        return R.ok().setMsg("删除成功");
    }

    /**
     * 批量删除(物理删除)
     * @param ids
     * @return
     */
    @PostMapping("/removeBatch")
    public Result<Object> removeBatch(@RequestBody List<Integer> ids) {
        ltService.removeBatchByIds(ids);
        return R.ok().setMsg("删除成功");
    }

    /**
     * 根据主键更新
     * @param lt
     * @return
     */
    @PutMapping("/lt")
    public Result<Object> updateById(@RequestBody Lt lt) {
        ltService.updateById(lt);
        return R.ok().setMsg("更新成功");
    }

    /**
     * 根据主键查找
     * @param id 主键
     * @return
     */
    @GetMapping("/lt/{id}")
    public Result<Lt> getById(@PathVariable("id") Integer id) {
        Lt lt = ltService.getById(id);
        return R.ok(lt);
    }

}
